// pages/index/drawback/drawback.js
var app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    items: [
      { name: '1', value: '商品数量与售出不一致' },
      { name: '2', value: '商品与售出不一致', checked: 'true' },
      { name: '3', value: '非商品问题' },
    ],
    show:false,
    data:'',
    targetid:'',
    targetreasion:'商品与售出不一致',
    baseimageurl: ''
  },

  radioChange: function (e) {
    let that = this;
    this.setData({
      targetreasion: that.data.items[e.detail.value -1].value
    })
    // console.log('radio发生change事件，携带value值为：', e.detail.value)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    app.post('/shop/reFundList').then(res=>{
      that.setData({
        data:res,
        baseimageurl: app.globalData.baseImageUrl
      })
    })
  },
  intoOrder:function(e){
    let id = e.currentTarget.dataset.orderid;
    wx.navigateTo({
      url: '../../order/order-detail/order-detail?id=' + id,
    })
  },
  no:function(e){
    let that = this;
    console.log(e)
    let id = e.currentTarget.dataset.id;
    that.setData({
      show: true,
      targetid: id
    });
  },
  ok:function(e){
    wx.showLoading({
      title: '退款中',
    })
    let that = this;
    let id = e.currentTarget.dataset.id;
    that.setData({
      targetid: id
    });
    app.post('/shop/reFundChangeState', { orderId: that.data.targetid,type:1}).then(res=>{
      wx.hideLoading();
      wx.showToast({
        title: '同意成功',
        success: res => {
          that.onLoad()
        }
      })
    },res=>{
      wx.hideLoading();
      wx.showToast({
        title: '同意失败',
        success: res => {
          that.onLoad()
        }
      })
    })
  },
  cancel:function(){
    let that = this;
    that.setData({
      show: false
    })
  },
  //拒绝
  confirm:function(e){
    let that = this;
    wx.showLoading({})
    app.post('/shop/reFundChangeState', { orderId: that.data.targetid, type: 2, reason: that.data.targetreasion}).then(res => {
      wx.hideLoading();
      wx.showToast({
        title: '拒绝成功',
        success: res => {
          that.setData({
            show: false
          })
          that.onLoad()
        }
      })
    },res=>{
      wx.hideLoading();
      wx.showToast({
        title: '拒绝失败',
        success: res => {
          that.setData({
            show: false
          })
          that.onLoad()
        }
      })
    })
  }
})